package com.onenine.app.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.onenine.app.R;
import com.onenine.app.model.PraiseMsgItem;
import com.onenine.app.utils.CHelper;
import com.onenine.app.utils.DataType;
import com.onenine.app.utils.GlideUtils;
import com.onenine.chat.util.SimpleCommonUtils;
import com.onenine.common.util.ApUtils;

public class PraiseMsgAdapter extends BaseQuickAdapter<PraiseMsgItem, BaseViewHolder> {

    private int mImgSize;

    public PraiseMsgAdapter() {
        super(R.layout.layout_msg_praise_item);
        mImgSize = ApUtils.getApp().getResources()
                .getDimensionPixelSize(R.dimen.dp68);
    }

    @Override
    protected void convert(final BaseViewHolder holder, final PraiseMsgItem msgItem) {
        GlideUtils.loadSrcImage(mContext, holder.getView(R.id.niv_avatar), msgItem.getPhoto());
        holder.setText(R.id.tv_name, msgItem.getNickName()).setText(R.id.tv_date, msgItem.getDate());
        TextView tvContent = holder.getView(R.id.tv_content);
        ImageView ivContent = holder.getView(R.id.iv_content);
        if (msgItem.getmType() == DataType.MSG_TEXT_TYPE) {
            //文字
            tvContent.setVisibility(View.VISIBLE);
            ivContent.setVisibility(View.GONE);
            SimpleCommonUtils.spannableEmoticonFilter(tvContent
                    , msgItem.getDescriptionContent());
        } else {
            //图片或视频
            ivContent.setVisibility(View.VISIBLE);
            tvContent.setVisibility(View.GONE);
            GlideUtils.loadSrcImage(mContext, ivContent
                    , CHelper.getOssThumbImageUrl(msgItem.getDescriptionContent(), mImgSize));
        }
    }

}
